package com.ziDingYiValidator;

import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/***
 * CheckPassword是自定的注解
 * String是根据你变量的属性类型来确定的，
 *   Integer age：则是  Integer
 *   List<String> 则是   List<String>
 */
public class TelValidator implements ConstraintValidator<CheckTel,String> {


    @Override
    public void initialize(CheckTel constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        Pattern pattern=Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$");
        if (StringUtils.isBlank(value)){
            return true;
        }else {
            Matcher matcher=pattern.matcher(value);
            return matcher.matches();
        }
    }
}
